<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
    </div>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="loading"
      :data="data"
      size="small"
      style="width: 100%;"
      stripe
      empty-text="暂无数据"
      highlight-current-row
      current-row-key="id"
    >
      <el-table-column prop="sid" label="学号"/>
      <el-table-column prop="sname" label="学生姓名"/>
      <el-table-column prop="remark" label="评分"/>
      <el-table-column prop="status" label="是否评价">
        <template slot-scope="scope">
          {{scope.row.status == 1 ? '是':'否'}}
        </template>
      </el-table-column>
      <el-table-column label="操作"
                       align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit" @click="comment(scope.row)">查看详细评分
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <e-form ref="form" @close="load"></e-form>
    <!--分页组件-->
    <el-row>
      <el-col :offset="10">
        <el-pagination
          :total="total"
          :current-page="params.offset"
          style="margin-top: 8px;"
          :page-sizes="[10, 20, 30, 50]"
          layout="total, prev, pager, next, sizes"
          @size-change="sizeChange"
          @current-change="pageChange"/>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import comment from '@/api/teacher/comment/comment'
  import courseComment from '@/api/teacher/comment/courseComment'
  import eForm from './form'

  export default {
    components: {
      eForm
    },
    data() {
      return {
        loading: true,
        total: 0,
        show: false,
        isAdd: false,
        params: {
          offset: 1,
          limit: 10,
          cid: null,
          tcId: null,
          commentId: null,
          sid:null,
        },
        data: null
      }
    },
    created() {
      this.params.commentId = this.$route.query.commentId
      this.params.cid = this.$route.query.cid
      this.load()
    },
    methods: {
      load() {
        comment.findStudentComment(this.params).then(res => {
          this.data = res.records
          this.loading = false
          this.currentPage = res.current
          this.total = res.realTotal
        }).catch(error => {
          this.loading = false
          this.$notify({
            title: '错误信息',
            message: '登录超时，请重新登录'
          })
          this.$router.push({path: '/login'})
        })
      },
      sizeChange(val) {
        this.params.limit = val
        this.load()
      },
      pageChange(val) {
        this.params.offset = val
        this.load()
      },
      add() {
        this.isAdd = true
        this.$refs.form.dialog = true
      },
      comment(val) {
        console.log(val)
        this.$refs.form.status = val.status;
        this.$refs.form.remark = val.remark;
        this.$refs.form.form['tmId'] = val.id;
        this.params.cid = val.cid;
        this.params.tcId = val.id;
        this.params.sid = val.sid;
        courseComment.queryStudentComment(this.params).then(res => {
          this.$refs.form.form = res
        })
        this.$refs.form.dialog = true
      },
      edit(data) {
        this.isAdd = false
        const _this = this.$refs.form
        _this.form = {
          id: data.id,
          classname: data.classname,
          collegeId: data.collegeId,
          specialtyId: data.specialtyId,
          gradeId: data.gradeId
        }
        _this.dialog = true
      },
      toQuery() {
        this.load()
      },
    }
  }
</script>

<style scoped>
  .status {
    color: green;
  }
</style>
